class Article < ApplicationRecord
  belongs_to :user, class_name: "User"
  validates :title, :presence => true
  validates :body, :presence => true
  has_many :version,                    dependent: :destroy, foreign_key: :article_id


  #simple version system need improvement
  def version
    @version ||= @artice.version
  end

  def versions
    @artice.versions
  end

  def first_version
    versions.first
  end

  #是否是本用户的文章
  def owned_by?(owner)
    return false unless owner.is_a? User
    user == owner
  end
end
